package com.joolun.web.controller.weixin;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.system.domain.WxPortal;
import com.joolun.system.service.IWxPortalService;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 小程序首页轮播图Controller
 * 
 * @author www.joolun.com
 * @date 2022-01-01
 */
@RestController
@RequestMapping("/system/portal")
public class WxPortalBannerController extends BaseController
{
    @Autowired
    private IWxPortalService wxPortalService;

    /**
     * 查询小程序首页轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('system:portal:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxPortal wxPortal)
    {
        startPage();
        List<WxPortal> list = wxPortalService.selectWxPortalList(wxPortal);
        return getDataTable(list);
    }

    /**
     * 导出小程序首页轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('system:portal:export')")
    @Log(title = "小程序首页轮播图", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WxPortal wxPortal)
    {
        List<WxPortal> list = wxPortalService.selectWxPortalList(wxPortal);
        ExcelUtil<WxPortal> util = new ExcelUtil<WxPortal>(WxPortal.class);
        return util.exportExcel(list, "portal");
    }

    /**
     * 获取小程序首页轮播图详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:portal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(wxPortalService.selectWxPortalById(id));
    }

    /**
     * 新增小程序首页轮播图
     */
    @PreAuthorize("@ss.hasPermi('system:portal:add')")
    @Log(title = "小程序首页轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxPortal wxPortal)
    {
        return toAjax(wxPortalService.insertWxPortal(wxPortal));
    }

    /**
     * 修改小程序首页轮播图
     */
    @PreAuthorize("@ss.hasPermi('system:portal:edit')")
    @Log(title = "小程序首页轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxPortal wxPortal)
    {
        return toAjax(wxPortalService.updateWxPortal(wxPortal));
    }

    /**
     * 删除小程序首页轮播图
     */
    @PreAuthorize("@ss.hasPermi('system:portal:remove')")
    @Log(title = "小程序首页轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wxPortalService.deleteWxPortalByIds(ids));
    }
}
